package com.ruoyi.business.controller;

import java.util.List;

import com.ruoyi.business.domain.vo.AuthBindingInfoReviewVO;
import com.ruoyi.business.domain.vo.CommonReviewVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.RepairEvents;
import com.ruoyi.business.service.IRepairEventsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报事报修Controller
 * 
 * @author asher
 * @date 2021-11-23
 */
@RestController
@RequestMapping("/business/repair_events")
public class RepairEventsController extends BaseController
{
    @Autowired
    private IRepairEventsService repairEventsService;

    /**
     * 查询报事报修列表
     */
    @PreAuthorize("@ss.hasPermi('business:repair_events:list')")
    @GetMapping("/list")
    public TableDataInfo list(RepairEvents repairEvents)
    {
        startPage();
        List<RepairEvents> list = repairEventsService.selectRepairEventsList(repairEvents);
        return getDataTable(list);
    }

    /**
     * 导出报事报修列表
     */
    @PreAuthorize("@ss.hasPermi('business:repair_events:export')")
    @Log(title = "报事报修", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RepairEvents repairEvents)
    {
        List<RepairEvents> list = repairEventsService.selectRepairEventsList(repairEvents);
        ExcelUtil<RepairEvents> util = new ExcelUtil<RepairEvents>(RepairEvents.class);
        return util.exportExcel(list, "报事报修数据");
    }

    /**
     * 获取报事报修详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:repair_events:query')")
    @GetMapping(value = "/{eventId}")
    public AjaxResult getInfo(@PathVariable("eventId") Long eventId)
    {
        return AjaxResult.success(repairEventsService.selectRepairEventsByEventId(eventId));
    }

    /**
     * 新增报事报修
     */
    @PreAuthorize("@ss.hasPermi('business:repair_events:add')")
    @Log(title = "报事报修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RepairEvents repairEvents)
    {
        return toAjax(repairEventsService.insertRepairEvents(repairEvents));
    }

    /**
     * 修改报事报修
     */
    @PreAuthorize("@ss.hasPermi('business:repair_events:edit')")
    @Log(title = "报事报修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RepairEvents repairEvents)
    {
        return toAjax(repairEventsService.updateRepairEvents(repairEvents));
    }

    /**
     * 删除报事报修
     */
    @PreAuthorize("@ss.hasPermi('business:repair_events:remove')")
    @Log(title = "报事报修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{eventIds}")
    public AjaxResult remove(@PathVariable Long[] eventIds)
    {
        return toAjax(repairEventsService.deleteRepairEventsByEventIds(eventIds));
    }

    /**
     * 推进报事报修
     */
    @Log(title = "推进报事报修", businessType = BusinessType.INSERT)
    @PostMapping("/handle")
    public AjaxResult review(@RequestBody CommonReviewVO commonReviewVO)
    {
        int i = repairEventsService.handleRepairEvents(commonReviewVO);
        if (i == 0) {
            return AjaxResult.error("操作失败");
        }
        return AjaxResult.success();
    }
}
